package com.findyou.controller;

import com.findyou.pojo.User;
import com.findyou.service.UserService;
import com.findyou.utils.Result;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Title: UserController
 * @Author 贾金博
 * @Package com.findyou.controller
 * @Date 2024/3/6 20:24
 * @description:
 */

@RestController
@RequestMapping("user")
@CrossOrigin // 跨域
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("login")
    public Result login(@RequestBody User user) { // 接受json参数
        Result result = userService.login(user);
        return result;
    }

    @GetMapping("getUserInfo")
    public Result getUserInfo(@RequestHeader String token) {
//        System.out.println("token = " + token);
        Result result = userService.getUserInfo(token);
        return result;
    }

    @PostMapping("checkUserName")
    public Result checkUserName(@Param("username") String username) {

        Result result = userService.checkUserName(username);
//        System.out.println("result = " + result);
        return result;
    }

    @PostMapping("regist")
    public Result regist(@RequestBody User user) {
//        System.out.println("user = " + user);
        Result result = userService.regist(user);
        return  result;
    }

    @GetMapping("checkLogin")
    public Result checkLogin(@RequestHeader String token) {
        Result result = userService.checkLogin(token);
        System.out.println("result = " + result);
        return result;
    }

}
